Using ISMAP and ISINDEX with MacHTTP

The following is a description of how to use ISINDEX and ISMAP with MacHTTP. ISINDEX is a tag returned at the beginning of a HTML document that indicates that the document accepts search arguments and returns some result of the search.

MacHTTP performs searches by executing AppleScript functions. So, you MUST have AppleScript installed to use either ISINDEX or ISMAP tags within HTML documents served by MacHTTP.

Important Note! Many of the following scripts depend on AppleScript extensions for performing text file I/O that are not part of the standard AppleScript distribution. These extensions (OSAXs) can be found in the "ScriptTools" package available from the usual Mac FTP sites. A reasonably current copy of ScriptTools can be downloaded from this server by clicking here.

Searching

This AppleScript shows a way to access the http_search_args variable, extracting search arguments for further processing.

-- This script demonstrates accessing searchable files from MacHTTP.
-- (What it really shows is how to pass arguments to AppleScripts.)
-- http_search_args is a predefined variable that is passed from the server
--  to the script and contains the user-supplied arguments. If the arguments
--  are empty, the script asks the WWW client to prompt for them. 
--  If arguments were passed, then the script behaves accordingly.
--  Note: the <ISINDEX> HTML tag is what tells the client the document is searchable
--    and arguments should be collected and passed. 

if http_search_args = "" then
	return "<ISINDEX><h2>Please enter the keyword to search for.</h2>"
else if http_search_args = "hello" then
	return "<h2>Hello, how are you?</h2>"
else
	return "<h2>Sorry, I don't understand '" & http_search_args & "'. Try 'hello' instead.</h2>"
end if

Using Maps

The following HTML document is a simple sample that shows how to present a clickable map. Note that it works in conjunction with the accompanying AppleScript to perform the map functions.

<title>Map</title><isindex><H1>Map</H1><A HREF="map.script"><IMG SRC="map.GIF" ismap></A><P>Click on the map above. 
<address>abc</address>

This is the AppleScript that interprets the search arguments containing the mouse click coordinates

-- Interactive Campus Map Script
--

to returnContents of returnFileName
        local fileText
        set fileText to ""
        try
                set refNum to open file alias returnFileName for reading
        on error
                return "<title>Script Error</title><h1>Couldn't find requested file</h1>"
        end try
        repeat
                try
                        set fileText to fileText & (read file refNum) & (ASCII character of 32)
                on error -- assume EOF hit
                        exit repeat
                end try
        end repeat
        close file refNum
        return fileText
end returnContents



if http_search_args = "" then
        returnContents of "MapDocument.html"
else
        set oldDelimiters to AppleScript's text item delimiters
        set AppleScript's text item delimiters to {","}
        set x to first text item of http_search_args as integer
        set y to second text item of http_search_args as integer
        set AppleScript's text item delimiters to oldDelimiters
        if (x > topLeftX) and (x < botRightX) and (y > topLeftY) and (y < botRightY) then
                returnContents of "HotSpotInfo.html"
        else 
                returnContents of "Error.html"
        end if
end if

Many thanks to Dennis Wilkinson at the University of Massachusetts Dartmouth who figured out how to convince MacHTTP to serve up maps.